package com.haidechizi.leetcode;

public class _452_用最少数量的箭引爆气球 {

    public int findMinArrowShots(int[][] points) {
        if (points == null || points.length == 0) {
            return 0;
        }
        // 排序
        sort(points);

        int count = 0;
        int left = points[0][0];
        int right = points[0][1];
        for (int i = 1; i < points.length; i++) {
            if (points[i][0] <= right) {
                left = points[i][0];
                if (points[i][1] < right) {
                    right = points[i][1];
                }
            } else {
                left = points[i][0];
                right = points[i][1];
                count++;
            }
        }
        count++;
        return count;
    }

    public void sort(int[][] points) {
        for (int j = 0; j < points.length; j++) {
            for (int i = 0; i < points.length - 1 - j; i++) {
                if (points[i][0] > points[i + 1][0]) {
                    int[] temp = points[i];
                    points[i] = points[i + 1];
                    points[i + 1] = temp;
                }
            }
        }

    }
}
